import {Handler} from "./Handler";
import {MapRenderer} from "../render/MapRenderer";
import {MapCamera} from "../render/MapCamera";

export class WheelHandler extends Handler {
    protected mapRenderer: MapRenderer;

    protected camera: MapCamera;

    disable(): void {
        this.map.container.removeEventListener('wheel', ev => this.onWheel(ev));
    }

    enable(): void {
        this.map.container.addEventListener('wheel', ev => this.onWheel(ev))
    }

    init(): void {
        this.mapRenderer = this.map.mapRenderer;
        this.camera = this.mapRenderer.camera;
    }

    private onWheel(ev: WheelEvent) {
        let dz = -ev.deltaY / 53 / 5;
        this.camera.zoomBy(dz);
    }
}
